package com.example.consumer018080.controller;

import com.example.consumer018080.bean.Depart;
import com.example.consumer018080.service.DepartService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/depart1")
public class DepartApi {

    @Autowired
    private DepartService departService;

    @PostMapping("/save")
    public boolean save(@RequestBody Depart depart){
        return departService.save(depart);
    }

    @PostMapping("/del")
    public boolean del(int id){
        return departService.del(id);
    }

    @PostMapping("/update")
    public boolean update(@RequestBody Depart depart){
        return departService.update(depart);
    }

    @GetMapping("/find/{id}")
    public Depart query(@PathVariable int id){
        return departService.query(id);
    }

    @GetMapping("/findAll")
    @HystrixCommand(fallbackMethod = "saveOrderFail")
    public List<Depart> findAll(){
        return departService.findAll();
    }

    @GetMapping("/info")
    public String getInfo(){
        return departService.getInfo();
    }

    //注意，方法签名一定要要和api方法一致
    public List<Depart> saveOrderFail(){
        System.out.println("controller中的降级方法");
        return null;
    }
}
